
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.table.DefaultTableModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Marwen
 */
public final class ListeClient extends javax.swing.JFrame {

    /**
     * Creates new form ListeClient
     */
    
        private Object[][] data;

    public ListeClient()  {
        
            initComponents();
            
            this.setLocationRelativeTo(null);
                this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                this.setTitle("Lise des clients ");
                tableClient.setEnabled(false);
                remplirliste();

    }
    public void viderListe(){
        DefaultTableModel model = (DefaultTableModel) tableClient.getModel();
        int n=model.getRowCount();
        for(int i=0;i<n;i++){
            model.removeRow(n-i-1);
        }
    }
    public void remplirliste(){
        try {
                    viderListe();
                    DefaultTableModel model = (DefaultTableModel) tableClient.getModel();
                    this.setContentPane(jScrollPane1);
                    this.tableClient.setRowHeight(35);
                    DbManip.requete = "SELECT ID_CLIENT, ID_ENTREPRISE,nom_client,prenom_client,adresse_client,tel_client,email_client,profession_client from client";
                    DbManip.executer(DbManip.requete);
                    int m = DbManip.rsmd.getColumnCount();
                    DbManip.rs.last();
                    int n = DbManip.rs.getRow();
                    int i = 0;
                    DbManip.rs.beforeFirst();
                    data = new Object[n][m];
                    while (DbManip.rs.next()) {
                        int id_client = DbManip.rs.getInt("id_client");
                        int ID_ENTREPRISE = DbManip.rs.getInt("ID_ENTREPRISE");
                        String NOM_CLIENT = DbManip.rs.getString("NOM_CLIENT").substring(0,DbManip.rs.getString("NOM_CLIENT").indexOf("  "));
                        String PRENOM_CLIENT = DbManip.rs.getString("PRENOM_CLIENT").substring(0,DbManip.rs.getString("PRENOM_CLIENT").indexOf("  "));
                        String ADRESSE_CLIENT = DbManip.rs.getString("ADRESSE_CLIENT").substring(0,DbManip.rs.getString("ADRESSE_CLIENT").indexOf("  "));
                        String TEL_CLIENT = DbManip.rs.getString("TEL_CLIENT").substring(0,DbManip.rs.getString("TEL_CLIENT").indexOf("  "));
                        String EMAIL_CLIENT = DbManip.rs.getString("EMAIL_CLIENT").substring(0,DbManip.rs.getString("EMAIL_CLIENT").indexOf("  "));
                        String PROFESSION_CLIENT = DbManip.rs.getString("PROFESSION_CLIENT").substring(0,DbManip.rs.getString("PROFESSION_CLIENT").indexOf("  "));             
                       // String type = DbManip.rs.getString("type").substring(0,DbManip.rs.getString("type").indexOf("  "));
                       // int quantite = DbManip.rs.getInt("quantite");
                        data[i][0] = id_client;
                        data[i][1] = ID_ENTREPRISE;
                        data[i][2] = NOM_CLIENT;
                        data[i][3] = PRENOM_CLIENT;
                        data[i][4] = ADRESSE_CLIENT;
                       
                        data[i][5] = TEL_CLIENT;
                        data[i][6] = EMAIL_CLIENT;
                        data[i][7] =PROFESSION_CLIENT;
        model.addRow(new Object[]{id_client, ID_ENTREPRISE, NOM_CLIENT, PRENOM_CLIENT, ADRESSE_CLIENT, TEL_CLIENT,EMAIL_CLIENT,PROFESSION_CLIENT});

                        i++;
                    }
        }
        catch (SQLException ex) {
            Logger.getLogger(ListeClient.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tableClient = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        tableClient.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID_CLIENT", "ID_Entreprise", "Nom client", "PRENOM CLIENT", "Adresse CLIENT", "Telephone Client", "Email Client", "Profession Client"
            }
        ));
        jScrollPane1.setViewportView(tableClient);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 644, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tableClient;
    // End of variables declaration//GEN-END:variables
}
